import {Component} from '@angular/core';
import {
    AlertController, IonicPage, LoadingController, NavController, NavParams, Platform,
    ToastController
} from 'ionic-angular';
import {SystemService} from "../../service/SystemService";
import {NotifyItemPage} from "../notify-item/notify-item";
import {UserManager} from "../../../framework/manager/UserManager";
import {BasePage} from "../../BasePage";
import {Log} from "../../../framework/utils/Log";

/**
 * Generated class for the NotifyPage page.
 *
 * See https://ionicframework.com/docs/components/#navigation for more info on
 * Ionic pages and navigation.
 */


@Component({
    selector: 'page-notify',
    templateUrl: 'notify.html',
    providers: [SystemService]
})
export class NotifyPage extends BasePage{
    private static TAG:string='NotifyPage';
    notifyList: Array<Object> = [];
    context: string;
    private _unitId: string;
    private _userId: string;

    constructor(public navCtrl: NavController, public navParams: NavParams, public sys: SystemService,public platform: Platform,
                public loadingCtrl: LoadingController,
                public toastCtrl: ToastController,
                public alertCtrl: AlertController) {
        super(platform, loadingCtrl, toastCtrl, alertCtrl);


    }

    ionViewDidLoad() {
        Log.w(NotifyPage.TAG,'ionViewDidLoad NotifyPage');
        this._unitId = UserManager.getInstance().user.unitId;
        this._userId = UserManager.getInstance().user.userId;
        this.getNotifyInfo();
    }

    getNotifyInfo() {

        let notifyInfo: any = {
            DanWeiBH: this._unitId,
            YongHuBH: this._userId
        };
        this.sys.getNotifyList(notifyInfo)
            .subscribe((res: any) => {
                Log.printObj(NotifyPage.TAG,'data==', res);
                if (res.msgCode == '1') {
                    this.notifyList = res.list;
                }else {
                    this.showError('数据请求失败');
                }
            }, error => {
                this.showError('数据请求失败');
            });
    }

    notifyHandler(id) {
        this.navCtrl.push(NotifyItemPage, {'id': id})
    }
}
